//
//  AgentDetailViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/6.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "AgentDetailViewController.h"
#import "Masonry.h"
#import "RentVieitor.h"
#import "Starview.h"
#import "HousingCell.h"
#import "AgentModel.h"
#import "AllHouseViewController.h"
#import "FangModel.h"
#import "HouseDetailViewController.h"
#import "RentHouseViewController.h"
#import "MJRefresh.h"


@interface AgentDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@end

@implementation AgentDetailViewController {
    
    CGFloat scal;
    NSString *_identify;
    UIScrollView *_scrollView;
    UIButton *lookBtn;
    UIImageView *hpView;
    UILabel *nameLabel;
    UILabel *numLabel;
    UILabel *evaluateLabel;
    UILabel *belongLabel;
    UILabel *beTextLabel;
    UILabel *knowLabel;
    UILabel *tagLabel;
    UILabel *tagLabel2;
    UILabel *tagLabel3;
    Starview *starView;
    UITableView *_tableview;

}

- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"经纪人详情";
    self.tabBarController.tabBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    self.data = [NSMutableArray array];
    
    scal = KWidth/375;
    if (scal > 1) {
        
        scal = 1;
        
    }
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight-45-64)];
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
    _scrollView.showsVerticalScrollIndicator = NO;
    
    
    [self.view addSubview:_scrollView];
    [self creatLeftView];
    [self creatview];
    [self creatEvaluateView];
    [self recommendView];
    [self creatTaBar];
    [self loadData];
    [self loadlistData];
}

//经纪人介绍
- (void)creatview {
    
    UIView *headView = [[UIView alloc] init];
//    headView.backgroundColor = [UIColor redColor];
    [_scrollView addSubview:headView];
    
    //分割线
    CALayer *MlineLayer13 = [CALayer layer];
    MlineLayer13.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
    MlineLayer13.frame = CGRectMake(15 ,110, KWidth-30, 1);
    [_scrollView.layer addSublayer:MlineLayer13];
    
    hpView = [[UIImageView alloc] init];
    hpView.image = [UIImage imageNamed:@"头像"];
    [headView addSubview:hpView];
    
    nameLabel = [[UILabel alloc] init];
    nameLabel.font = [UIFont systemFontOfSize:17];
    nameLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    nameLabel.text = @"";
    [headView addSubview:nameLabel];
    
    numLabel = [[UILabel alloc] init];
    numLabel.font = [UIFont systemFontOfSize:13];
    numLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    numLabel.text = @"";
    [headView addSubview:numLabel];
    [self setRichNumberWithLabel:numLabel Color:[UIColor redColor] FontSize:13];
    
    
    evaluateLabel = [[UILabel alloc] init];
    evaluateLabel.font = [UIFont systemFontOfSize:13];
    evaluateLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    evaluateLabel.text = @"专业能力:5分 响应速度:5分 服务态度:5分";
    [headView addSubview:evaluateLabel];
    
     NSRange range = [evaluateLabel.text rangeOfString:@"0.00"];
    [self setTextColor:evaluateLabel FontNumber:[UIFont systemFontOfSize:12] AndRange:range AndColor:[Utils colorConvertFromString:@"#333333"]];
    

    [self setRichNumberWithLabel:evaluateLabel Color:[UIColor orangeColor] FontSize:15];
    
    UIImageView *interImgView = [[UIImageView alloc] init];
    interImgView.image = [UIImage imageNamed:@"中介"];
    [headView addSubview:interImgView];
    
    UIImageView *estateView = [[UIImageView alloc] init];
    estateView.image = [UIImage imageNamed:@"小区"];
    [headView addSubview:estateView];
    
    belongLabel = [[UILabel alloc] init];
    belongLabel.text = @"所属中介";
    belongLabel.font = [UIFont systemFontOfSize:10];
    belongLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:belongLabel];
    
    beTextLabel = [[UILabel alloc] init];
    beTextLabel.text = @"";
    beTextLabel.font = [UIFont systemFontOfSize:10];
    beTextLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:beTextLabel];
    
    knowLabel = [[UILabel alloc] init];
    knowLabel.text = @"暂无数据";
    knowLabel.font = [UIFont systemFontOfSize:10];
    knowLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:knowLabel];
    
    tagLabel = [[UILabel alloc] init];
    tagLabel.text = @"";
    tagLabel.backgroundColor = [UIColor colorWithRed:213/255.0 green:235/255.0 blue:251/255.0 alpha:1];
    tagLabel.font = [UIFont systemFontOfSize:10];
    tagLabel.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:tagLabel];
    
    tagLabel2 = [[UILabel alloc] init];
    tagLabel2.text = @"";
    tagLabel2.backgroundColor = [UIColor colorWithRed:213/255.0 green:235/255.0 blue:251/255.0 alpha:1];
    tagLabel2.font = [UIFont systemFontOfSize:10];
    tagLabel2.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:tagLabel2];
    
    tagLabel3 = [[UILabel alloc] init];
//    tagLabel3.text = @"兰溪香谷";
//    tagLabel3.backgroundColor = [UIColor colorWithRed:213/255.0 green:235/255.0 blue:251/255.0 alpha:1];
    tagLabel3.font = [UIFont systemFontOfSize:10];
    tagLabel3.textColor = [Utils colorConvertFromString:@"#333333"];
    [headView addSubview:tagLabel3];
    
    starView = [[Starview alloc] initWithFrame:CGRectMake(11.5*scal, headView.frame.size.height-20, 65*scal+22.5*scal, 12)];
    starView.index = 3;
    [headView addSubview:starView];

    
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view.mas_left);
        make.leading.equalTo(self.view.mas_leading);
        make.size.mas_equalTo(CGSizeMake(KWidth, 110));
    }];
    
    [hpView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(headView.mas_top).with.offset(15);
        make.left.equalTo(headView.mas_left).with.offset(22.5*scal);
        make.size.mas_equalTo(CGSizeMake(65*scal, 65*scal));
        
    }];
    
    [starView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(headView.mas_bottom).with.offset(-15);
        make.left.equalTo(headView.mas_left).with.offset(11*scal);
        make.size.mas_equalTo(CGSizeMake(65*scal+22*scal, 10));
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(headView.mas_top).with.offset(15);
        make.left.equalTo(hpView.mas_right).with.offset(22.5*scal);
        make.right.equalTo(numLabel.mas_left).with.offset(-15*scal);
        make.height.equalTo(@20);

    }];
    
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(headView.mas_top).with.offset(15);
        make.left.equalTo(nameLabel.mas_right).with.offset(15*scal);
        make.right.equalTo(headView.mas_right).with.offset(-10);
        make.height.equalTo(@20);
    }];
    
    [evaluateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(nameLabel.mas_bottom).with.offset(10);
        make.left.equalTo(hpView.mas_right).with.offset(22.5*scal);
        make.height.equalTo(@10);
        make.right.equalTo(headView.mas_right);
    }];
    
    
    [interImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(evaluateLabel.mas_bottom).with.offset(10);
        make.left.equalTo(hpView.mas_right).with.offset(22.5*scal);
        make.right.equalTo(belongLabel.mas_left).with.offset(-3);
        make.height.equalTo(@10);
        
    }];
    
    [belongLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(evaluateLabel.mas_bottom).with.offset(10);
        make.left.equalTo(interImgView.mas_right).with.offset(3);
        make.right.equalTo(beTextLabel.mas_left).with.offset(-3);
        make.height.equalTo(@10);
        
    }];
    
    
    [beTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(evaluateLabel.mas_bottom).with.offset(10);
        make.left.equalTo(belongLabel.mas_right).with.offset(3);
        make.right.equalTo(headView.mas_right).with.offset(-3);
        make.height.equalTo(@10);
        
    }];
    
    [estateView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(interImgView.mas_bottom).with.offset(10);
        make.left.equalTo(hpView.mas_right).with.offset(22.5*scal);
        make.right.equalTo(knowLabel.mas_left).with.offset(-3);
        make.height.equalTo(@10);
        
    }];
    
    [knowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(interImgView.mas_bottom).with.offset(10);
        make.left.equalTo(estateView.mas_right).with.offset(3);
        make.right.equalTo(tagLabel.mas_left).with.offset(-3);
        make.height.equalTo(@10);
        
    }];
    
    [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(interImgView.mas_bottom).with.offset(10);
        make.left.equalTo(knowLabel.mas_right).with.offset(3);
        make.right.equalTo(tagLabel2.mas_left).with.offset(-3);
        make.height.equalTo(@10);
    }];
    
    [tagLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(interImgView.mas_bottom).with.offset(10);
        make.left.equalTo(tagLabel.mas_right).with.offset(3);
        make.right.equalTo(tagLabel3.mas_left).with.offset(-3);
        make.height.equalTo(@10);
    }];
    
    [tagLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(interImgView.mas_bottom).with.offset(10);
        make.left.equalTo(tagLabel2.mas_right).with.offset(3);
        make.right.equalTo(headView.mas_right).with.offset(-3);
        make.height.equalTo(@10);
    }];

    
}

- (void)loadData {
    
    NSString *url = [NSString stringWithFormat:@"%@agent/info",Main_Url];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",self.sn,APPKEY_URL,url];
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSDictionary *param = @{
                            
                            @"sn":self.sn,
                            @"sign":md5String
                            
                            };
    
    //    [param setValue:md5String forKey:@"sign"];
    
    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        [_scrollView.mj_header endRefreshing];
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            NSDictionary *dic = response[@"data"];
            dic = [Utils nullDic:dic];
            AgentModel *model = [AgentModel mj_objectWithKeyValues:dic];
            [self reloadData:model];
        }else {
            [APPDELEGATE showPro:response[@"message"]];
        }
        
        
    } failure:^(NSError *err) {
        
        [_scrollView.mj_header endRefreshing];
        
    }];

}

- (void)reloadData:(AgentModel *)_model {
    
    nameLabel.text = _model.name;
    [hpView sd_setImageWithURL:[NSURL URLWithString:_model.image] placeholderImage:[UIImage imageNamed:@"头像"]];
    numLabel.text = [NSString stringWithFormat:@"在租房源%@套",_model.amount];
//    [self setRichNumberWithLabel:numLabel Color:[UIColor redColor] FontSize:13];
    beTextLabel.text = _model.company;
    
    NSString *professional = [_model.point_professional substringToIndex:1];
    NSString *speed = [_model.point_speed substringToIndex:1];
    NSString *service = [_model.point_service substringToIndex:1];
    
    evaluateLabel.text = [NSString stringWithFormat:@"专业能力%@分,响应速度%@分,服务态度%@分",professional,speed,service];
    [self setRichNumberWithLabel:evaluateLabel Color:[UIColor redColor] FontSize:13];
    
    starView.index = 4;
    
    UILabel *label = (UILabel *)[_scrollView viewWithTag:200];
    UILabel *label2 = (UILabel *)[_scrollView viewWithTag:201];
    UILabel *label3 = (UILabel *)[_scrollView viewWithTag:202];
    label.text = _model.deal_num;
    label2.text = _model.look_num;
    label3.text = @"100%";
}

- (void)loadlistData {

    NSString *url = [NSString stringWithFormat:@"%@fang/list",Main_Url];
    NSDictionary *dic = @{
                          @"category":@"1001",
                          @"city":@"103",
                          @"rows":@"2",
                          @"agent":self.sn
                          };
    NSString *str = [ReturnSign returnSignWithDic:dic];
    NSString *md5String = [NSString stringWithFormat:@"%@%@%@",str,APPKEY_URL,url];
    
    //32位小写
    
    //    NSString *nickname = [nameText.text stringByAddingPercentEscapesUsingEncoding:
    //                          NSUTF8StringEncoding];
    
    md5String = [LCMD5Tool MD5ForLower32Bate:md5String];
    NSMutableDictionary * param = [NSMutableDictionary dictionaryWithDictionary:dic];
    [param setObject:md5String forKey:@"sign"];
    //    [param setValue:md5String forKey:@"sign"];
    __weak typeof(self)WeakSelf = self;
    [AFHttpTool requestWihtUrl:url params:param success:^(id response) {
        
        [_scrollView.mj_header endRefreshing];
        if ([response[@"code"] isEqualToString:@"10000"]) {
            
            NSArray *dataArray = response[@"data"];
            for (NSDictionary *dic2 in dataArray) {
               NSDictionary *dic = [Utils nullDic:dic2];
                
                FangModel *model = [[FangModel alloc] init];
                [model setValuesForKeysWithDictionary:dic];
                [WeakSelf.data addObject:model];
            }
            
            [_tableview   reloadData];
            
        }else {
            [APPDELEGATE showPro:response[@"message"]];
        }
        
        
    } failure:^(NSError *err) {
        [_scrollView.mj_header endRefreshing];
        
    }];
}

//评分
- (void)creatEvaluateView {
    
    NSArray *numArray = @[@"3",@"2138",@"98%"];
    NSArray *titleArray = @[@"近三个月成交(套)",@"近三个月看房(次)",@"好评率"];
    CGFloat width = KWidth/3-2;
    CGFloat hight = 70/2;
    for (int i=0; i<3; i++) {
        
        UILabel *numLabel2 = [[UILabel alloc] initWithFrame:CGRectMake((width+1)*i, 111, width, hight)];
        numLabel2.text = numArray[i];
        numLabel2.tag = 200+i;
        numLabel2.textAlignment = NSTextAlignmentCenter;
        numLabel2.font = [UIFont boldSystemFontOfSize:20];
        numLabel2.textColor = [Utils colorConvertFromString:@"#a7d831"];
        [_scrollView addSubview:numLabel2];
        
        
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake((width+1)*i, 101+hight, width, hight)];
        textLabel.text = titleArray[i];
        textLabel.textAlignment = NSTextAlignmentCenter;
        textLabel.font = [UIFont systemFontOfSize:11];
        textLabel.textColor = [Utils colorConvertFromString:@"#666666"];
        [_scrollView addSubview:textLabel];
        
        //分割线
        if (i<2) {
            
            CALayer *MlineLayer13 = [CALayer layer];
            MlineLayer13.backgroundColor = [[Utils colorConvertFromString:@"#d0d0d0"] CGColor];
            MlineLayer13.frame = CGRectMake((width+1)*(i+1) ,120, 1, 50);
            [_scrollView.layer addSublayer:MlineLayer13];
        }
       
    }
    
    CALayer *MlineLayer13 = [CALayer layer];
    MlineLayer13.backgroundColor = [[Utils colorConvertFromString:@"#F2F2F2"] CGColor];
    MlineLayer13.frame = CGRectMake(0 ,180, KWidth, 10);
    [_scrollView.layer addSublayer:MlineLayer13];
    
}

//推荐房源
- (void)recommendView {
    
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 190, KWidth, 300) style:UITableViewStylePlain];
    _tableview.showsVerticalScrollIndicator = NO;
    _tableview.showsHorizontalScrollIndicator = NO;
    _tableview.userInteractionEnabled = YES;
    _tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _identify = @"_Cell";
    
    [_tableview registerClass:[HousingCell class] forCellReuseIdentifier:_identify];
    [_scrollView addSubview:_tableview];
    
    lookBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    lookBtn.frame = CGRectMake(20, _tableview.frame.size.height+_tableview.frame.origin.y+5, KWidth-40, 40);
    [lookBtn setBackgroundColor:[Utils colorConvertFromString:@"#eaeaea"]];
    [lookBtn setTitleColor:[Utils colorConvertFromString:@"#999999"] forState:UIControlStateNormal];
    [lookBtn setTitle:@"查看所有在租房源" forState:UIControlStateNormal];
    lookBtn.layer.masksToBounds = YES;
    [lookBtn addTarget:self action:@selector(lookAction) forControlEvents:UIControlEventTouchUpInside];
    lookBtn.layer.cornerRadius = 2;
    [_scrollView addSubview:lookBtn];
    
//    _scrollView.contentSize = CGSizeMake(KWidth,  _tableview.frame.size.height+_tableview.frame.origin.y+45+84);
    
    _scrollView.contentSize = CGSizeMake(KWidth, 565);
}

- (void)headerRefresh {
    
    [self.data removeAllObjects];
    if (self.data == nil) {
        self.data = [NSMutableArray array];
    }
    [self loadData];
    [self loadlistData];
}

- (void)creatTaBar {
    
    UIView *tabView = [[UIView alloc] initWithFrame:CGRectMake(0,KHeight-45-64, KWidth, 45)];
    CALayer *MlineLayer14 = [CALayer layer];
    MlineLayer14.backgroundColor = [[Utils colorConvertFromString:@"#F2F2F2"] CGColor];
    MlineLayer14.frame = CGRectMake(0 ,1, KWidth, 1);
    [tabView.layer addSublayer:MlineLayer14];
    
    [self.view addSubview:tabView];
    NSArray *imgArray = @[@"收-藏",@"添加-(1)",@"分享"];
    NSArray *titleArray = @[@"收藏",@"添加",@"分享"];
    CGFloat width = 55;
    for (int i=0; i<imgArray.count; i++) {
        
        
        UIControl *control = [[UIControl alloc] initWithFrame:CGRectMake((width+1)*i,1,55,44)];
        control.tag = 100+i;
        control.userInteractionEnabled = YES;
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((54-12)/2,8,15,15)];
        imgView.image = [UIImage imageNamed:imgArray [i]];
        [control addSubview:imgView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 23, width, 20)];
        label.text = titleArray[i];
        label.textColor = [Utils colorConvertFromString:@"#fc7f33"];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:12];
        [control addSubview:label];
        
        [control addTarget:self action:@selector(tabSelectAction:) forControlEvents:UIControlEventTouchUpInside];
        [tabView addSubview:control];
        
        //分割线
        if (i<2) {
            
            CALayer *MlineLayer13 = [CALayer layer];
            MlineLayer13.backgroundColor = [[Utils colorConvertFromString:@"#f2f2f2"] CGColor];
            MlineLayer13.frame = CGRectMake((width+1)*(i+1) ,0, 1, 40);
            [tabView.layer addSublayer:MlineLayer13];
        }
    }
    
    UIButton *inquiryBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    inquiryBtn.frame = CGRectMake(width*3, 1 ,KWidth-width*3, 44);
    [inquiryBtn setBackgroundColor:[Utils colorConvertFromString:@"#fc7f33"]];
    [inquiryBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [inquiryBtn setTitle:@"咨询经纪人" forState:UIControlStateNormal];
    inquiryBtn.layer.masksToBounds = YES;
    [inquiryBtn addTarget:self action:@selector(inquiryAction) forControlEvents:UIControlEventTouchUpInside];
    [tabView addSubview:inquiryBtn];

//    CGFloat width = (KWidth - 210*Main_Scale)/3;
//    CGFloat heigh =
    
}



//资讯经纪人
- (void)inquiryAction {
    
}

//查看所有房源
- (void)lookAction {
    
    RentHouseViewController *rentVc = [[RentHouseViewController alloc] init];
    rentVc.agent = self.sn;
    [self.navigationController pushViewController:rentVc animated:YES];
    
}

- (void)tabSelectAction:(UIControl *)control {
    
    [APPDELEGATE showPro:@"功能完善中"];
}

#pragma mark -- 协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.data.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HousingCell *cell = [tableView dequeueReusableCellWithIdentifier:_identify forIndexPath:indexPath];
    
    if (self.data.count > indexPath.row) {
        cell.model = self.data[indexPath.row];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 110+40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HouseDetailViewController *detailVc = [[HouseDetailViewController alloc] init];
    if (self.data.count > indexPath.row) {
        FangModel *model = self.data[indexPath.row];
        detailVc.sn = model.sn;
    }
    
    [self.navigationController pushViewController:detailVc animated:YES];
}


- (void)creatLeftView {
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(-5, 0, 10, 15);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(0, 0, 20, 17);
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(noticeAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)setRichNumberWithLabel:(UILabel*)label Color:(UIColor *)color FontSize:(CGFloat)size {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSString *temp = nil;
    for(int i =0; i < [attributedString length]; i++) {
        temp = [label.text substringWithRange:NSMakeRange(i, 1)];
        if ([self isPureInt:temp]) {
            [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                             color, NSForegroundColorAttributeName,
                                             [UIFont systemFontOfSize:size],NSFontAttributeName, nil]
                                      range:NSMakeRange(i, 1)];
        }
    }
    label.attributedText = attributedString;
}

- (BOOL)isPureInt:(NSString *)string {
    NSScanner *scan = [NSScanner scannerWithString:string];
    int value;
    return [scan scanInt:&value] && [scan isAtEnd];
}

//设置不同字体颜色
-(void)setTextColor:(UILabel *)label FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label.text];
    //设置字号
    [str addAttribute:NSFontAttributeName value:font range:range];
    //设置文字颜色
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    
    label.attributedText = str;
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

//通知
- (void)noticeAction {
    
}

@end
